
fi.internetix.s2nq.NotificationQueueItem = Class.create({
  initialize: function (text, options) {
    this._options = Object.extend({
      timeout: -1
    },options||{});
    
    this._removeLinkClickListener = this._onRemoveLinkClick.bindAsEventListener(this);
    
    this.domNode = new Element("div", {
      className: "notificationQueueItem"
    });
    
    this._removeLink = new Element("a", {
      className: "notificationQueueItemRemoveLink"
    });
    
    this.domNode.appendChild(new Element("span", {
      className: "notificationQueueItemText"
    }).update(text));
    this.domNode.appendChild(this._removeLink);
    
    if (this._options.className) {
      this.domNode.addClassName(this._options.className);
    }
    
    this._text = text;
    this._removed = false;
    
    Event.observe(this._removeLink, "click", this._removeLinkClickListener);
  },
  deinitialize: function () {
    Event.stopObserving(this._removeLink, "click", this._removeLinkClickListener);
    
    this.domNode.remove();
  },
  setup: function (notificationQueue) {
    this._notificationQueue = notificationQueue;
    if (this._options.timeout > 0)
      this._scheduleRemoval();
  },
  getText: function () {
    return this._text;
  },
  remove: function () {
    this._remove();
  },
  _remove: function () {
    if (this._removed === false) {
      this._removed = true;
      this._notificationQueue.removeItem(this);
    }
  },
  _scheduleRemoval: function () {
    var _this = this;
    setTimeout(function () {
      _this._remove();
    }, this._options.timeout);
  },  
  _cancelScheduledRemoval: function () {
    
  },
  _onRemoveLinkClick: function (event) {
    this._remove();
  }
});